package com.example.zzm.yuejian03.Model;

import com.example.zzm.yuejian03.Bean.ActivBean;
import com.example.zzm.yuejian03.Iface.ActivdetailsIface;
import com.example.zzm.yuejian03.Listener.TListener;
import com.example.zzm.yuejian03.Server;
import com.example.zzm.yuejian03.Service.Service;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class ActivdetailsModel implements ActivdetailsIface {

    private Retrofit retrofit;


    public ActivdetailsModel(){
        retrofit=new Retrofit.Builder()
                .baseUrl(Server.BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

    }
    @Override
    public void getActivdetailss(int activity_id,final TListener listener) {
        Service service
                =retrofit.create(Service.class);
        Call<ActivBean> call
                =service.getActivdetails(activity_id);


        call.enqueue(new Callback<ActivBean>() {
            @Override
            public void onResponse(Call<ActivBean> call, Response<ActivBean> response) {
                if(response.isSuccessful() && response!=null)
                {  listener.onResponse(response.body());
                }
                else   listener.onFail("on response fail");
            }
            @Override
            public void onFailure(Call<ActivBean> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });

    }
}
